<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!--只在模块名下面有效 -->
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>意见反馈列表</title>
	<jsp:include page="../../import.jsp" flush="true" />
	<script type="text/javascript">
		var grid = null;
		var callback = function () {
			grid.reload();
		};
		$(function () {
			initForm();
			initGridDB();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
			searchBtnEvent();
			clearBtnEvent();
			$('#closeAttachmentsView').click(function() {
				closeAttachmentsView();
			});
		});

		//清空按钮事件
		function clearBtnEvent(){
			$("#clearBtn").click(function(event) {
				clearLigerForm("searchBar");
			});
		}

		//初始化表单
		function initForm(){
			$("#searchBar").ligerForm();
		}

		//查询按钮事件
		function searchBtnEvent(){
			$("#searchBtn").click(function(event) {
				var form = new liger.get("searchBar");
				var data = form.getData();
				for (name in data){
					grid.setParm(name,data[name]);
				};
				grid.reload();
			});
		}

		//初始化列表
		function initGridDB(){
			$("#ligergrid1").ligerGrid({
				url: '<%=path%>/spl/splAppOpinionReaction/initList.do',
				method : 'get',
				columns: [
					{ display: '手机号', name: 'phone', width: 150 , align: 'center', enabledSort:true},
					{ display: '姓名', name: 'usrRlNm', width: 100 , align: 'center', enabledSort:true},
					{ display: '反馈内容', name: 'opinionDesc', minWidth: 200 , align: 'center', isEllipsis: false, enabledSort:true},
					{ display: '反馈时间', name: 'crtTm', render:renderDate, width: 150 , align: 'center', enabledSort:true},
                    { display: '系统类型', name: 'equipSysTyp', minWidth: 80, align: 'center', enabledSort:true},
                    { display: 'APP版本号', name: 'appVersion', minWidth: 80, align: 'center', enabledSort:true},
                    {
						display : '附件',
						name : '',
						minWidth : 200,
						enabledSort : false,
						render : function(rowdata, rowindex, value) {
							var h="";
		                		h+='<a class="sq-button-hasicon" href="javascript:viewAttachments(';
		                        h+="'"+rowdata.id+"'";
		                        h+=')"><i class="sqBtnIco_1"></i>查看</a>';
		                    return h;
						}
					}
				],
				pageSize:10,
				root:'rows',
				record:'total',
				rownumbers: true,
                checkbox:true,
				hideLoadButton : true,
				width: '100%',
				height:'100%',
				heightDiff:-2,
				fixedCellHeight: false
			});
			grid = liger.get("ligergrid1");
			grid.setHeight(100);
		}

		//格式化时间
		function renderDate(rowdata, index, value){
			var dateStr = "";
			if(null != value){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
			}
			return dateStr;
		}
        //删除数据
        function removeByIds(){
            var selectedRows = grid.getSelectedRows();
            if(selectedRows.length == 0){
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
                return;
            }

            var _ids = [];
            for ( var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }
            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:{ids:JSON.stringify(_ids)},
                    url: '<%=path%>/spl/splAppOpinionReaction/removeByIds.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        
		function viewAttachments(_id) {
			var urlArray = null;
			//alert(_id);
			$.ajax({
				type : 'get',
				dataType : 'json',
				data : {
					id : _id
				},
				url : '<%=path%>/spl/splAppOpinionReaction/viewAttachments.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : '正在查询附件...',
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						//console.log(msg.data);
						urlArray = msg.data;
						if (urlArray != null) {
							for (img in urlArray) {
								//console.log(urlArray[img]);
								var li = '<li><img  src="' + urlArray[img] + '" alt=""></li>';
								$('#dowebok').append(li);
							}
							//$('#dowebok').viewer();
							var viewer = new Viewer(document.getElementById('dowebok'), {
								hidden : function() {
									//alert('hidden');
									urlArray = null;
									$('#dowebok').html('');
									viewer.destroy();
								},
							});
							viewer.show();
						} else {
							$.ligerDialog.SQalert({
								content : '该记录没有附件...',
								SQ_type : "warn"
							});
						}
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				}
			});
		}
	</script>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div class="searchArea">
			<form id="searchBar">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_33">
					<div class="label">手机号</div>
					<div class="field">
						<input name="phone" id="phone" type="text" class="ui-textbox" value="">
					</div>
				</div>
				<div class="fieldBox col_33">
					<div class="label">姓名</div>
					<div class="field">
						<input name="usrRlNm" id="usrRlNm" type="text" class="ui-textbox" value="">
					</div>
				</div>
				<div class="fieldBox  col_33">
					<div class="label">反馈时间</div>
					<div class="field">
						<input ligerui="width: 120" name="crtTmMin"
							id="crtTmMin" type="text" class="ui-datepicker" value=""
							validate="{required:true}"> - <input
							ligerui="width: 120" name="crtTmMax" id="crtTmMax"
							type="text" class="ui-datepicker" value=""
							validate="{required:true}">
					</div>
				</div>
			</div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
               <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
				<span id="delBtn" class="sq-button sq-button-hasicon" onclick="removeByIds();"><i class="sqBtnIco_7"></i>删除</span>
               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
        </form>
		</div>
		<div id="ligergrid1" class="sq-grid"></div>

		<!-- 附件展示 -->
		<ul id="dowebok" style="display:none">
		</ul>
	</div>
</body>
</html>
